home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / VARREC.MOD < prev    next >
Text File  |  1989-01-18  |  3KB  |  85 lines

  1.                                         (* Chapter 11 - Program 3 *)
  2. MODULE VarRec;
  3.  
  4. FROM InOut   IMPORT WriteString, WriteInt, WriteLn;
  5.  
  6. TYPE   KindOfVehicle = (Car,Truck,Bicycle,Boat);
  7.  
  8.        Vehicle = RECORD
  9.          OwnerName   : ARRAY[0..25] OF CHAR;
  10.          GrossWeight : CARDINAL;
  11.          Value       : REAL;
  12.          CASE WhatKind : KindOfVehicle OF
  13.            Car     : Wheels  : CARDINAL;
  14.                      Engine  : ARRAY[0..12] OF CHAR |
  15.            Truck   : Motor   : ARRAY[0..8] OF CHAR;
  16.                      Tires   : CARDINAL;
  17.                      PayLoad : CARDINAL |
  18.            Bicycle : Tyres   : INTEGER |
  19.            Boat    : PropBlades : INTEGER;
  20.                      Sail    : BOOLEAN;
  21.                      Power   : ARRAY[0..8] OF CHAR;
  22.          END; (* of CASE *)
  23.        END;   (* of record *)
  24.  
  25. VAR   Sunfish, Ford, Schwinn, Mac : Vehicle;
  26.  
  27. BEGIN
  28.    Ford.OwnerName := "Walter";         (* Fields defined in order *)
  29.    Ford.GrossWeight := 5750;
  30.    Ford.Value := 2595.00;
  31.    Ford.WhatKind := Truck;
  32.    Ford.Motor := "V8";
  33.    Ford.Tires := 18;
  34.    Ford.PayLoad := 12000;
  35.  
  36.    WITH Sunfish DO
  37.       WhatKind := Boat;      (* Fields defined in random order *)
  38.       Sail := TRUE;
  39.       PropBlades := 3;
  40.       Power := "Wind";
  41.       GrossWeight := 375;
  42.       Value := 1300.00;
  43.       OwnerName := "Herman and George";
  44.    END;
  45.  
  46.    Ford.Engine := "Flathead";         (* Tag-field not defined yet *)
  47.    Ford.WhatKind := Car;              (* but it must be before it  *)
  48.                                       (* can be referred to        *)
  49.    Ford.Wheels := 4;        (* Notice that the non-variant part is *)
  50.                             (* not redefined here.                 *)
  51.  
  52.    Mac := Sunfish;    (* Entire record copied, including tag-field *)
  53.  
  54.    IF Ford.WhatKind = Car THEN                (* This should print *)
  55.       WriteString(Ford.OwnerName);
  56.       WriteString(" owns the car with the ");
  57.       WriteString(Ford.Engine);
  58.       WriteString(' engine.');
  59.       WriteLn;
  60.    END;
  61.  
  62.    IF Sunfish.WhatKind = Bicycle THEN     (* This should not print *)
  63.       WriteString("The sunfish is a bicycle");
  64.       WriteLn;
  65.    END;
  66.  
  67.    IF Mac.WhatKind = Boat THEN                (* This should print *)
  68.       WriteString("The Mac is now a boat with");
  69.       WriteInt(Mac.PropBlades,2);
  70.       WriteString(" propeller blades.");
  71.       WriteLn;
  72.    END;
  73. END VarRec.
  74.  
  75.  
  76.  
  77.  
  78. (* Result of execution
  79.  
  80. Walter owns the car with the Flathead engine.
  81. The Mac is now a boat with 3 propeller blades.
  82.  
  83. *)
  84.  
  85.